package org.chenbingkang.esper.client;

import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;
import org.chenbingkang.esper.event.PersonEvent;
import org.chenbingkang.esper.listener.PersonEventListener;

public class EsperClient {

    private EPServiceProvider engine;

    public EsperClient() {
        //obtain an engine instance
        this.engine = EPServiceProviderManager.getDefaultProvider();
        //System.out.println(engine.getURI());
    }

    public void personEventProcess() {

        //tell the engine about the event type
        engine.getEPAdministrator().getConfiguration().addEventType(PersonEvent.class);
        //create an epl statement
        String epl = "select name, age from PersonEvent";
        EPStatement statement = engine.getEPAdministrator().createEPL(epl);
        statement.addListener(new PersonEventListener());

    }

    public void send(Object event) {

        engine.getEPRuntime().sendEvent(event);

    }
}
